#pragma once

#include "geometry.h"
#include "DCELMesh.h"
#include "Event.h"

class VoronoiDiagram : public Graph
{
public:
	VoronoiDiagram() : beachline_(NULL),time_(0.0) {}
	~VoronoiDiagram();

	DCELMesh& getDiagram() { return mesh_; }
	int generateDiagram(double time);
	void insertFace(Site site);
	void insertVertex(DCELHalfEdge *e, double time, Vector p);
	void preprocess();

protected:
	EventQueue queue_;
	std::vector<Event*> events_;
	DCELMesh mesh_;
	DCELHalfEdge *beachline_;
	double time_;

	int isOnEdge(DCELHalfEdge *e, Vector site, Vector& p, bool bPoint);
	void insertSiteFace(DCELHalfEdge *e, Site site);
	void insertCircleFace(DCELHalfEdge *e, Site site, Vector p);

	void checkCircleEvent(DCELHalfEdge *e);
	void intersectNext(DCELHalfEdge *e, double time, Vector& p);
	void intersectNext(DCELHalfEdge *e, double time, double& y);
	void caculateBeachline(double time);
	
};